package wqh.global;

import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * Created by devts on 2017/1/5.
 */
public class GlobalXkDevice {

    private static final Set<Long> transmissionDeviceCode = Collections.synchronizedSet(new HashSet<Long>());

    public static synchronized void addDevice(long code){
        transmissionDeviceCode.add(code);
    }

    public static synchronized void removeDevice(long code){
        transmissionDeviceCode.remove(code);
    }

    public static synchronized Set<Long> getTransmissionDeviceCodeSet(){
        return transmissionDeviceCode;
    }

    public static synchronized boolean exist(long code){
        Iterator<Long> iterator= transmissionDeviceCode.iterator();
        while (iterator.hasNext()){
            long _code = iterator.next();
            if(_code == code) return true;
        }
        return false;
    }
}
